/**
 * Copyright 2009-2011 xiaonei.com All right reserved.
 * This software is the confidential and proprietary information of Xiaonei.com ("Confidential Information"). 
 * You shall not disclose such Confidential Information and shall use it only in accordance with the terms of the license agreement you entered into with Xiaonei.com.
 * Create by XiaoNeiAntiSpamTeam
 *
 */

package com.xiaonei.testice.testxcestorm;

import java.util.HashMap;
import java.util.Map;

import com.xiaonei.xce.storm.XceStormAdapter;
import com.xiaonei.xce.storm.XceStormListener;

/**
 * @ClassName: XceStormExample
 * @Description: XceStormExample类
 * @author shaohui.liu shaohui.liu@opi-corp.com
 * @date Feb 21, 2010 3:55:02 PM
 * 
 */
public class XceStormExample {

    private final static String topicName = "topicName";

    /**
     * 单例的时候一定要注意类变量初始化的顺序
     */
    private static XceStormExample instance = new XceStormExample();

    public static XceStormExample getInstance() {
        return instance;
    }

    private XceStormExample() {
        /**** 实现监听方法类 ***/
        XceStormListener listener = new XceStormListenerImpl();
        /*** 注册监听方法 ***/
        XceStormAdapter.getInstance().subscribe(topicName, listener);
    }

    public void Messagenotify() {
        Map<String, String> props = new HashMap<String, String>();
        // add key-value here!
        XceStormAdapter.getInstance().notify(topicName, props);
    }

    class XceStormListenerImpl extends XceStormListener {

        /* (非 Javadoc)
         * <p>Title: handle</p>
         * <p>Description: </p>
         * @param context
         * @see com.xiaonei.xce.storm.XceStormListener#handle(java.util.Map)
        */
        @Override
        public void handle(Map<String, String> context) {
            // add code here!
        }
    }
}
